const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    car_list: [],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onShow: function (options) {
    this.getGoodsList();
  },
  getGoodsList: function () {
    app.ihttpGet('https://www.58zltc.com/api.php/Car/carList/openid/' + app.globalData.openid, res=>{
      this.setData({
        car_list: res.data
      })
    })
  },
  editCar: function(e){
    wx.navigateTo({
      url: 'add?type=edit&id=' + e.target.dataset.id,
    })
  },
  delCar: function (e) {
    var that = this;
    wx.showModal({
      title: '提示',
      content: '确定要删除该车型？',
      success: function (res) {
        if (res.confirm) {
          wx.showLoading({
            title: '删除中……',
          })
          app.ihttpGet('https://www.58zltc.com/api.php/Goods/del/openid/' + app.globalData.openid + '/id/' + e.currentTarget.dataset.id, res => {
            if (res.data.err_code > 0) {
              wx.showToast({
                title: res.data.err_msg,
              })
            } else {
              wx.showToast({
                title: res.data.err_msg,
                icon: 'success'
              })
              that.getGoodsList();
            }
          })
        }
      }
    })
  }
})